package explicitStateChecks;

public class TCPConnection {

	private int conState;

	public static final int STATE_CLOSED = 0;
	public static final int STATE_ESTABLISHED = 1;
	
	public static final int ERR_ALREADY_CLOSED = 2;
	public static final int SUCCESS = 3;
	
	public TCPConnection(int conState) {
		this.conState = conState;
	}

	public int close(){
		switch (conState) { 
		case STATE_CLOSED: 
			// already closed, do nothing 
			return ERR_ALREADY_CLOSED; 
		case STATE_ESTABLISHED: 
			// close connection 
			conState = STATE_CLOSED; 
			return SUCCESS;
		default:
			throw new IllegalArgumentException("Illegal State");
		} 
	}

}
